﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using smartphone.App_Code;

namespace smartphone.UserControls
{
    public partial class AdminNewsList : System.Web.UI.UserControl
    {
        private News news = new News();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Visible = false;
            if (!IsPostBack)
            {
                if (Request.QueryString["NewsID"] == null)
                {
                    this.Visible = true;
                    BindGrid();
                }
                
            }
        }

        /// <summary>
        /// lay tin tuc load vao grid view
        /// </summary>
        private void BindGrid()
        {
            GridViewNewsList.DataSource = news.GetAllNewsAdmin();
            GridViewNewsList.DataBind();
        }

        protected void GridViewNewsList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string id = GridViewNewsList.DataKeys[e.RowIndex].Value.ToString();

            bool success = news.DeleteNews(Int32.Parse(id));
            GridViewNewsList.EditIndex = -1;

            LabelInform.Text = success ? "Xóa thành công" : "Xoá không thành công";

            BindGrid();
        }

    }
}